package com.tradeplus.consumer;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.tradeplus.security.model.User;
import com.tradeplus.security.service.UserDetailsService;
import com.tradeplus.util.JSONView;
import com.tradeplus.util.TPLController;

public class ConsumerController extends TPLController {
	
	private UserDetailsService userDetailsService;
	
	public void setUserDetailsService(UserDetailsService userDetailsService) {
		this.userDetailsService = userDetailsService;
	}


	public ModelAndView InserUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
		request.getParameter("password");
		User user = new User();
		user.setUsername(request.getParameter("username"));
		user.setPassword(request.getParameter("password"));
		userDetailsService.save(user);
		
		HashMap userMap = new HashMap();
		userMap.put("user", "new");
		
		return new ModelAndView(new JSONView(), userMap);
		
	}
	
	
	/**
     * Load Login view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    public ModelAndView Login(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return new ModelAndView("/consumer/consumer_login",new HashMap());
    }

}
